#coding=utf-8
from django import forms
from django.forms import ModelForm, Textarea, TextInput,TimeInput
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User  

from models import Blog, Comment, LeaveAMsg, PicComment

EMPTY_TITLE_ERROR = u"标题不能为空"
EMPTY_BODY_ERROR = u'内容不能为空'
EMPTY_COMMENT_ERROR = u"评论不能为空"
EMPTY_MSG_ERROR = u"留言不能为空"

class BlogForm(ModelForm):
    class Meta:
        model = Blog
        fields = ('title', 'body',)
        widgets = {
            'title':TextInput(attrs = {
                'placeholder':'title',
                'class':'title-form',
            }),
            'body':Textarea(attrs = {
                'cols':100,
                'rows':10,
                'class':'body-form',
                'placeholder':'body',
            }),
            
        }
        error_messages = {
            'title':{
                'required':EMPTY_TITLE_ERROR
                },
            'body':{
                'required':EMPTY_BODY_ERROR
                }      
        }
    def save(self, for_user):
        self.instance.author = for_user
        return super(BlogForm, self).save()
    
class CommentForm(ModelForm):
    class Meta:
        model = Comment
        fields = ('content',)
        widgets = {
            'content':Textarea(attrs = {
                'cols':90,
                'rows': 3,
                'class':'comment-form',
                'placeholder':u'请输入评论。。。',
            }),
        }
        error_messages = {
            'content':{
                'required':EMPTY_COMMENT_ERROR
            }
        }
        
    def save(self, for_blog):
        self.instance.blog = for_blog
        return super(CommentForm, self).save()
    
class LeaveAMsgForm(ModelForm):
    class Meta:
        model = LeaveAMsg
        fields = ('content',)
        widgets = {
            'content':Textarea(attrs = {
                'cols':90,
                'rows': 3,
                'class':'comment-form',
                'placeholder':u'请输入留言...',
            }),
        }
        error_messages = {
            'content':{
                'required':EMPTY_MSG_ERROR
            }
        }
        
class PicCommentForm(ModelForm):
    class Meta:
        model = PicComment
        fields = ('content',)
        widgets = {
            'content':Textarea(attrs = {
                'cols':90,
                'rows': 3,
                'class':'comment-form',
                'placeholder':u'请输入评论。。。',
            }),
        }
        error_messages = {
            'content':{
                'required':EMPTY_COMMENT_ERROR
            }
        }